function [m, v, o] = mean_var(x)
% our own variance and mean function..... use with the Press et al. tools.
% 12/2/98 P. Manis
% Corrected "two pass" forumla from Press et al. , P617.
v = 0;
ep = 0;
m = 0; 

n = length(x);
if(length(x) == 1)
   m = x;
   o = 1;
   return;
end;
o = 0;
for j = 1:n
   if(~isnan(x(j)))
      o = o + 1;
      m = m + x(j);
   end;
end;
if(o == 0)
   m = NaN;
   v = NaN;
   return;
end;
m = m / o;
for j=1:n
   if(~isnan(x(j)))
      s = x(j) - m;
	   ep = ep + s;
   	v = v + s*s;
   end;
end
if(o == 1)
   v = (v-ep*ep/o);
else
   v = (v-ep*ep/o)/(o-1);
end;
return
